home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 767 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. From: peter@magna.com.au (Peter J Brock)
  2. Message-ID: <4ijj74$mp@kettle.magna.com.au>
  3. X-Original-Date: Mon, 18 Mar 1996 12:02:09 GMT
  4. Path: in1.uu.net!bounce-back
  5. Date: 18 Mar 96 21:59:15 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Template issue in MS VC++ 4.0, Non Standard?
  9. Organization: Me
  10. Reply-To: peter@magna.com.au
  11. X-Newsreader: Forte Free Agent v0.55
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBEAgUBMU3cyeEDnX0m9pzZAQFioQF4/y4bn1YKTIstQqzL5TIllG2NWI8FJQWZ
  14.     mO/2XXH1pQWAQMKqbtuRe3+69GXOGVk=
  15.     =DIZY
  16.  
  17. The following code illustrates a bug in the implementation of
  18. templates in MS Visual C++ 4.0.
  19.  
  20. //___________begin code sample__________________________
  21. // test.cpp
  22.  
  23. template <class T>
  24. class VeryTesting
  25. {     
  26.     public: 
  27.         VeryTesting();
  28.         T& operator()();
  29.         T     m_T;
  30. };
  31.  
  32. template <class T>
  33. inline
  34. VeryTesting<T>::VeryTesting () 
  35. {
  36. }
  37.  
  38. template <class T>
  39. inline T& 
  40. VeryTesting<T>::operator ()()
  41. {
  42.     return m_T;
  43. }
  44.  
  45. //  Uncomment this block of code and it all works!
  46. // template VeryTesting<double>;
  47.  
  48. class A
  49. {
  50. public :
  51.     A(){}
  52.     ~A(){}
  53.  
  54.     VeryTesting<double>& test(VeryTesting<double>& fdTest)
  55.     {
  56.         fdTest() = 5.0; //error C2064: term does not evaluate to a function
  57.         return fdTest;
  58.     }
  59. };
  60.  
  61. main()
  62. {
  63.     VeryTesting<double> f;
  64.     f() = 5.0;
  65.     A aObject;
  66.     aObject.test(f);
  67. }
  68. //___________end code sample___________________________
  69.  
  70.  
  71. The problem is that VeryTesting<double> is not instantiated correctly
  72. by the MS Visual C++ 4.0 compiler. This results in the error message
  73. that says function fdTest() does not evaluate to a function.
  74.  
  75. The code compiles under Borland 4.5.
  76.  
  77. So leads one to the question of how will compilers be vetted against a
  78. standard when it comes?
  79.  
  80. Cheers,
  81. Peter J Brock    http://www.magna.com.au/~peter
  82.  
  83. ---
  84. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  85. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  86. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  87. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  88. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  89.